********************************************************************************
*** figure_est.do (21.11.2024)
*** REPLICATION FILES OF TABLES AND FIGURES
*** Brox, Enzo; Goller, Daniel
*** Tournaments, Contestant Heterogeneity and Performance
********************************************************************************

clear all
set more off


********************************************************************************
*****************************DEFINE DIRECTORIES*********************************

cd ""


	
********************************************************************************
********************************LOAD DATA***************************************	
	
use DCHaP, clear


********************************************************************************
******************************DEFINE MACROS*************************************

local var_f_1 "i.Round i.tourn_id i.Fav_id"
local var_u_1 "i.Round i.tourn_id i.Und_id"
local var_f_2 "Fav_rankN_lagged Und_rankN_lagged i.tourn_id i.Round i.Fav_id"
local var_u_2 "Fav_rankN_lagged Und_rankN_lagged i.tourn_id i.Round i.Und_id"
local var_f_3 "Fav_starts Fav_rankN_lagged Und_rankN_lagged Fav_years_playing Und_years_playing Fav_home Und_home i.tourn_id i.Round i.Fav_id"
local var_u_3 "Fav_starts Fav_rankN_lagged Und_rankN_lagged Fav_years_playing Und_years_playing Fav_home Und_home i.tourn_id i.Round i.Und_id"
local var_c_2 "Fav_rankN_lagged Und_rankN_lagged i.tourn_id i.Round i.Fav_id i.Und_id"
local var_c_3 "Fav_starts Fav_rankN_lagged Und_rankN_lagged Fav_years_playing Und_years_playing Fav_home Und_home i.tourn_id i.Round i.Fav_id i.Und_id"
local var_f_4 "i.tourn_id i.Round Fav_av_lagged Fav_starts Fav_rankN_lagged Und_rankN_lagged Fav_years_playing Und_years_playing Fav_home Und_home "
local var_u_4 "i.tourn_id i.Round Und_av_lagged Fav_starts Fav_rankN_lagged Und_rankN_lagged Fav_years_playing Und_years_playing Fav_home Und_home"
local var_f_5 "i.Round i.Fav_yr_id Fav_starts Und_rankN_lagged Und_years_playing Fav_home Und_home"
local var_u_5 "i.Round i.Und_yr_id Fav_starts Fav_rankN_lagged Fav_years_playing Fav_home Und_home"
local var_of_3 "OFav_starts OFav_rankN_lagged OUnd_rankN_lagged OFav_years_playing OUnd_years_playing OFav_home OUnd_home i.tourn_id i.Round i.OFav_id"
local var_ou_3 "OFav_starts OFav_rankN_lagged OUnd_rankN_lagged OFav_years_playing OUnd_years_playing OFav_home OUnd_home i.tourn_id i.Round i.OUnd_id"


********************************************************************************
********************************************************************************

***Est for Fig 3

***** Heterogeneities (2parts)
*Experience
reg Fav_av9 ratio_av_FU `var_f_3' if Fav_years_playing<21,vce(cluster Fav_id)
estimates store F_av9_3e_z1

reg Fav_av9 ratio_av_FU `var_f_3' if Fav_years_playing>20,vce(cluster Fav_id)
estimates store F_av9_3e_z2

reg Und_av9 ratio_av_FU `var_u_3' if Und_years_playing<19,vce(cluster Und_id)
estimates store U_av9_3e_z1

reg Und_av9 ratio_av_FU `var_u_3' if Und_years_playing>18,vce(cluster Und_id)
estimates store U_av9_3e_z2


*Ability
reg Fav_av9 ratio_av_FU `var_f_3' if Fav_rank_lagged>19,vce(cluster Fav_id)
estimates store F_av9_3a_z1

reg Fav_av9 ratio_av_FU `var_f_3' if Fav_rank_lagged<20,vce(cluster Fav_id)
estimates store F_av9_3a_z2

reg Und_av9 ratio_av_FU `var_u_3' if Und_rank_lagged>70,vce(cluster Und_id)
estimates store U_av9_3a_z1

reg Und_av9 ratio_av_FU `var_u_3' if Und_rank_lagged<71,vce(cluster Und_id)
estimates store U_av9_3a_z2


*Pricemoney
reg Fav_av9 ratio_av_FU `var_f_3' if price_money_rescal<0.04,vce(cluster Fav_id)
estimates store F_av9_3p_z1

reg Fav_av9 ratio_av_FU `var_f_3' if price_money_rescal>0.04,vce(cluster Fav_id)
estimates store F_av9_3p_z2

reg Und_av9 ratio_av_FU `var_u_3' if price_money_rescal<0.04,vce(cluster Und_id)
estimates store U_av9_3p_z1

reg Und_av9 ratio_av_FU `var_u_3' if price_money_rescal>0.04,vce(cluster Und_id)
estimates store U_av9_3p_z2




* Panel A:  to LaTeX
estout U_av9_3e_z1 U_av9_3e_z2 U_av9_3a_z1 U_av9_3a_z2 U_av9_3p_z1 U_av9_3p_z2 using "figure3_est.tex", style(tex) ///
    cells(b(star fmt(3)) se(fmt(3) par)) label starlevels(* .1 ** .05 *** .01) ///
	keep(ratio_av_FU) ///
			    refcat(ratio_av_FU "\noalign{\smallskip}\textit{Panel A: Underdog performance}", nolabel) ///	
    varlabels(ratio_av_FU "Ability ratio") ///
			  mlabels("(1)" "(2)" "(3)" "(4)" "(5)" "(6)") ///
prehead("\resizebox{\columnwidth}{!}{%" "\begin{tabular}{l r r r r r r} \toprule \toprule & \multicolumn{2}{c}{Experience} & \multicolumn{2}{c}{Ability} & \multicolumn{2}{c}{Prize money} \\" "& \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high} & \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high} & \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high}\\" "\cmidrule(lr){2-7}" ) ///
    collabels(none) replace posthead("\midrule") 
	


* Panel B: to LaTeX
estout F_av9_3e_z1 F_av9_3e_z2 F_av9_3a_z1 F_av9_3a_z2 F_av9_3p_z1 F_av9_3p_z2 using "figure3_est.tex", style(tex) ///
    cells(b(star fmt(3)) se(fmt(3) par)) label starlevels(* .1 ** .05 *** .01) ///
	keep(ratio_av_FU) ///
		refcat(ratio_av_FU " \noalign{\smallskip}\textit{Panel B: Favorite performance}", nolabel) ///
    varlabels(ratio_av_FU "Ability ratio") ///
			  stats(N, fmt(%9.0fc) labels("\midrule \noalign{\smallskip}N")) ///
			postfoot("\bottomrule \bottomrule" "\end{tabular}%" "}")  ///
			collabels(none) mlabels(none) append



********************************************************************************
********************************************************************************


***Est for Figure A.1


reg Fav_win ratio_av_FU `var_f_3' if Fav_years_playing<21,vce(cluster Fav_id)
estimates store Fw_3e_z1

reg Fav_win ratio_av_FU `var_f_3' if Fav_years_playing>20,vce(cluster Fav_id)
estimates store Fw_3e_z2

reg Fav_win ratio_av_FU `var_f_3' if Fav_rank_lagged>19,vce(cluster Fav_id)
estimates store Fw_3a_z1

reg Fav_win ratio_av_FU `var_f_3' if Fav_rank_lagged<20,vce(cluster Fav_id)
estimates store Fw_3a_z2

reg Fav_win ratio_av_FU `var_f_3' if price_money_rescal<0.04,vce(cluster Fav_id)
estimates store Fw_3p_z1

reg Fav_win ratio_av_FU `var_f_3' if price_money_rescal>0.04,vce(cluster Fav_id)
estimates store Fw_3p_z2



* Panel A1:  to LaTeX
estout Fw_3e_z1 Fw_3e_z2 Fw_3a_z1 Fw_3a_z2 Fw_3p_z1 Fw_3p_z2 using "figurea1_est.tex", style(tex) ///
    cells(b(star fmt(3)) se(fmt(3) par)) label starlevels(* .1 ** .05 *** .01) ///
	keep(ratio_av_FU) ///
			    refcat(ratio_av_FU "\noalign{\smallskip}\textit{Favorite win}", nolabel) ///	
    varlabels(ratio_av_FU "Ability ratio") ///
			  mlabels("(1)" "(2)" "(3)" "(4)" "(5)" "(6)") ///
prehead("\resizebox{\columnwidth}{!}{%" "\begin{tabular}{l r r r r r r} \toprule \toprule & \multicolumn{2}{c}{Experience} & \multicolumn{2}{c}{Ability} & \multicolumn{2}{c}{Prize money} \\" "& \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high} & \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high} & \multicolumn{1}{c}{low} & \multicolumn{1}{c}{high}\\" "\cmidrule(lr){2-7}" ) ///
    collabels(none) replace posthead("\midrule") ///
			postfoot("\bottomrule \bottomrule" "\end{tabular}%" "}")  
	


*END
